<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var ws = new WebSocket('wss://javascript.info/article/websocket/demo/hello')

      ws.onopen = function (evt) {
        console.log('Connection open ...')
        ws.send('Hello WebSockets!')
      }
      ws.onmessage = function (evt) {
        console.log('Received Message: ' + evt.data)
        ws.close()
      }
      ws.onclose = function (evt) {
        console.log('Connection closed.')
      }
    </script>
  </body>
</html>
